package com.zmj.sy.mom.srv.aps.controller;

import com.zmj.sy.mom.srv.aps.bean.bo.AreaDetail;
import com.zmj.sy.mom.srv.aps.bean.vo.base.*;
import com.zmj.sy.mom.srv.aps.bean.vo.report.*;
import com.zmj.sy.mom.srv.aps.service.ReportService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.Map;

@RequiredArgsConstructor
@Api(tags = "报表")
@RestController
@RequestMapping("/report")
public class ReportController {

    private final ReportService reportService;

    @ApiOperation("套料报表-零件列表")
    @GetMapping("/nestPart")
    public BasePageResVo<ReportProductionPartResVo> productionPart(ReportProductionPartReqVo reqVo) {
        return reportService.productionPart(reqVo);
    }

    /**
     * @Description: 套料报表-零件列表(添加新查询条件)
     * @author: hejiahui
     * @since: 2024/10/25 16:58
     */
    @ApiOperation("套料报表-零件列表(添加新查询条件)")
    @PostMapping("/nestPartPost")
    public BasePageResVo<ReportProductionPartResVo> productionPartPost(@RequestBody ReportProductionPartReqVo reqVo) {
        return reportService.productionPartPost(reqVo);
    }

    @ApiOperation("套料报表-零件列表-关联订单")
    @GetMapping("/nestPartOrder")
    public BasePageResVo<ReportProductionPartOrderResVo> productionPartOrder(ReportProductionPartOrderReqVo reqVo) {
        return reportService.productionPartOrder(reqVo);
    }

    @ApiOperation("套料报表-零件列表-关联订单(添加新查询条件)")
    @GetMapping("/nestPartOrderPost")
    public BasePageResVo<ReportProductionPartOrderResVo> nestPartOrderPost(BasePlmIdPageReqVo reqVo) {
        return reportService.productionPartOrderPost(reqVo);
    }

    @ApiOperation("套料报表-零件列表-关联套料")
    @GetMapping("/nestPartNest")
    public BasePageResVo<ReportProductionPartNestResVo> productionPartNest(ReportProductionPartNestReqVo reqVo) {
        return reportService.productionPartNest(reqVo);
    }

    @ApiOperation("套料报表-零件列表-关联套料(添加新查询条件)")
    @GetMapping("/nestPartNestPost")
    public BasePageResVo<ReportProductionPartNestResVo> nestPartNestPost(BasePlmIdPageReqVo reqVo) {
        return reportService.productionPartNestPost(reqVo);
    }

    @ApiOperation("套料报表-订单列表")
    @GetMapping("/nestOrder")
    public BasePageResVo<ReportProductionOrderResVo> productionOrder(ReportProductionOrderReqVo reqVo) {
        return reportService.productionOrder(reqVo);
    }

    /**
     * @Description: 套料报表-订单列表(添加新查询条件)
     * @author: hejiahui
     * @since: 2024/10/26 15:58
     */
    @ApiOperation("套料报表-订单列表(添加新查询条件)")
    @PostMapping("/nestOrderPost")
    public BasePageResVo<ReportProductionOrderResVo> productionOrderPost(@RequestBody ReportProductionOrderReqVo reqVo) {
        return reportService.productionOrderPost(reqVo);
    }

    @ApiOperation("套料报表-订单列表-关联零件")
    @GetMapping("/nestOrderPart")
    public BasePageResVo<ReportProductionOrderPartResVo> productionOrderPart(ReportProductionOrderPartReqVo reqVo) {
        return reportService.productionOrderPart(reqVo);
    }

    @ApiOperation("套料报表-订单列表-关联套料")
    @GetMapping("/nestOrderNest")
    public BasePageResVo<ReportProductionOrderNestResVo> productionOrderNest(ReportProductionOrderNestReqVo reqVo) {
        return reportService.productionOrderNest(reqVo);
    }

    @ApiOperation("套料报表-套料列表")
    @GetMapping("/nestNest")
    public BasePageResVo<ReportProductionNestResVo> productionNest(ReportProductionNestReqVo reqVo) {
        return reportService.productionNest(reqVo);
    }

    /**
     * @Description: 套料报表-套料列表(添加新查询条件)
     * @author: hejiahui
     * @since: 2024/10/28 10:57
     */
    @ApiOperation("套料报表-套料列表(添加新查询条件)")
    @PostMapping("/nestNestPost")
    public BasePageResVo<ReportProductionNestResVo> productionNestPost(@RequestBody ReportProductionNestReqVo reqVo) {
        return reportService.productionNestPost(reqVo);
    }

    @ApiOperation("套料报表-套料列表-关联零件")
    @GetMapping("/nestNestPart")
    public BasePageResVo<ReportProductionNestPartResVo> productionNestPart(BaseIdReqVo reqVo) {
        return reportService.productionNestPart(reqVo);
    }

    @ApiOperation("套料报表-套料列表-关联钢板")
    @GetMapping("/nestNestPlate")
    public BasePageResVo<ReportProductionNestPlateResVo> productionNestPlate(BaseIdReqVo reqVo) {
        return reportService.productionNestPlate(reqVo);
    }

    @ApiOperation("套料报表-套料列表-工序")
    @GetMapping("/nestNestPhase")
    public BasePageResVo<ReportProductionNestPhaseResVo> productionNestPhase(BaseIdReqVo reqVo) {
        return reportService.productionNestPhase(reqVo);
    }

    @ApiOperation("套料报表-套料列表-统计值")
    @GetMapping("/nestNestStat")
    public BasePageResVo<ReportProductionNestStatResVo> productionNestStat(BaseIdReqVo reqVo) {
        return reportService.productionNestStat(reqVo);
    }

    @ApiOperation("生产订单-左侧树-产品订单")
    @GetMapping("/proOrderTree")
    public BaseListResVo<ReportProOrderTreeResVo> productionOrderTree(ReportProOrderTreeReqVo reqVo) {
        if (reqVo.getHistory() == null) {
            reqVo.setHistory(false);
        }

        return reportService.productionOrderTree(reqVo);
    }

    @ApiOperation("生产订单-右上角-组件、零件、外购件列表")
    @GetMapping("/partList")
    public BaseListResVo<ReportPartListResVo> partList(ReportPartListReqVo reqVo) {
        return reportService.partList(reqVo);
    }

    @ApiOperation("生产订单-右上角-零件统计数据")
    @GetMapping("/partTotal")
    public ReportPartStatResVo partTotal(ReportPartStatReqVo reqVo) {
        return reportService.partCount(reqVo);
    }

    @ApiOperation("生产订单-右上角-订单信息")
    @GetMapping("/proOrderList")
    public BaseListResVo<ReportProOrderListResVo> proOrderList(ReportProOrderListReqVo reqVo) {
        if(StringUtils.hasText(reqVo.getSerialCode())){
            reqVo.setSerialCode(reqVo.getSerialCode().toUpperCase().trim());
        }
        return reportService.proOrderList(reqVo);
    }

    @ApiOperation("生产订单-右上角-能力需求")
    @GetMapping("/proAbility")
    public BaseListResVo<ReportProAbilityResVo> proAbility(ReportProAbilityReqVo reqVo) {
        return reportService.proAbility(reqVo);
    }

    @ApiOperation("生产订单-右上角-批次信息")
    @GetMapping("/proSubList")
    public BaseListResVo<ReportProSubListResVo> proSubList(ReportProSubListReqVo reqVo) {
        return reportService.proSubList(reqVo);
    }

    @ApiOperation("生产订单-订单统计")
    @GetMapping("/proOrderStat")
    public ReportProOrderStatResVo proOrderStat(ReportProOrderStatReqVo reqVo) {
        if(StringUtils.hasText(reqVo.getSerialCode())){
            reqVo.setSerialCode(reqVo.getSerialCode().toUpperCase().trim());
        }
        return reportService.proOrderStat(reqVo);
    }

    @ApiOperation("生产订单-右下角-制造")
    @GetMapping("/proPhase")
    public BaseListResVo<ReportProPhaseResVo> proPhase(ReportProPhaseReqVo reqVo) {
        return reportService.proPhase(reqVo);
    }

    @ApiOperation("生产订单-右下角-物料项目")
    @GetMapping("/proPlate")
    public BaseListResVo<ReportProPlateResVo> proPlate(ReportProPlateReqVo reqVo) {
        return reportService.proPlate(reqVo);
    }


    @ApiOperation("生产订单-右下角-工作准备")
    @GetMapping("/proPre")
    public BaseListResVo<ReportProPreResVo> proPre(ReportProPreReqVo reqVo) {
        return reportService.proPre(reqVo);
    }

    @ApiOperation("生产订单-右下角-库存信息")
    @GetMapping("/proStock")
    public BaseListResVo<ReportProStockResVo> proStock(ReportProStockReqVo reqVo) {
        return reportService.proStock(reqVo);
    }

    @ApiOperation("生产订单-右下角-组件信息")
    @GetMapping("/proAssembly")
    public BaseListResVo<ReportProAssemblyResVo> proAssembly(ReportProAssemblyReqVo reqVo) {
        return reportService.proAssembly(reqVo);
    }

    @ApiOperation("生产订单-右下角-领料信息")
    @GetMapping("/proPick")
    public BaseListResVo<ReportProPickResVo> proPick(ReportProPickReqVo reqVo) {
        return reportService.proPick(reqVo);
    }

    @ApiOperation("生产订单-右下角-零件图")
    @GetMapping("/proPartDraw")
    public ReportProPartDrawResVo proPartDraw(ReportProPartDrawReqVo reqVo) {
        return reportService.proPartDraw(reqVo);
    }

    @ApiOperation("生产订单-左上角-查询plmId类型")
    @GetMapping("/proSearchPlmId")
    public ReportProSearchPlmIdResVo proSearchPlmId(ReportProSearchPlmIdReqVo reqVo) {
        return reportService.proSearchPlmId(reqVo);
    }

    @ApiOperation("生产订单-左上角-通过零件ID查询整个树的父亲")
    @GetMapping("/proLocationPart")
    public BaseListResVo<ReportProOrderTreeResVo> proLocationPart(ReportProLocaltionPartReqVo reqVo) {
        return reportService.proLocationPart(reqVo);

    }

    @ApiOperation("生产订单-左侧树-全部展开")
    @GetMapping("/proExpandTree")
    public BaseListResVo<ReportProOrderTreeResVo> proExpandTree(ReportProExpandTreeReqVo reqVo) {
        return reportService.proExpandTree(reqVo);
    }

    @ApiOperation("板材领取-领取列表")
    @PostMapping("/pickList")
    public BaseListResVo<ReportPickListResVo> pickList(@RequestBody ReportPickListReqVo reqVo) {
        return reportService.pickList(reqVo);
    }

    @ApiOperation("板材领取-已套料零件")
    @GetMapping("/pickNest")
    public BaseListResVo<ReportPickNestDrawResVo> pickNest(BaseIdReqVo reqVo) {
        return reportService.pickNest(reqVo);
    }

    @ApiOperation("板板领取-图纸")
    @GetMapping("/pickDraw")
    public ReportPickDrawResVo pickDraw(ReportPickDrawReqVo reqVo) {
        return reportService.pickDraw(reqVo);
    }

//    @ApiOperation("生产订单-左侧树-产品订单-关联产品")
//    @GetMapping("/proOrderTreePro")
//    public BaseListResVo<ReportProOrderTreeProResVo> productionOrderTreePro(ReportProOrderTreeProReqVo reqVo) {
//        return reportService.productionOrderTreePro(reqVo);
//    }

    @ApiOperation("钢板切割报表")
    @GetMapping("/plateCutReport")
    public BaseListResVo<ReportWorkPlaceCutResVo> plateCutReport(ReportWorkPlaceCutReqVo reqVo) {
        return reportService.plateCutReport(reqVo);
    }

    @ApiOperation("分拣报表")
    @GetMapping("/plateSortReport")
    public BasePageResVo<ReportWorkPlaceSortResVo> plateSortReport(ReportWorkPlaceSortReqVo reqVo) {
        return reportService.plateSortReport(reqVo);
    }

    @ApiOperation("分拣钢板下的零件")
    @GetMapping("/plateSortPart")
    public BasePageResVo<ReportWorkPlaceSortPartResVo> plateSortPart(ReportWorkPlaceSortPartReqVo reqVo) {
        return reportService.plateSortPart(reqVo);
    }

    @ApiOperation("套料-零件-关联工具")
    @GetMapping("/nestPartTool")
    public BaseListResVo<ReportNestPartToolResVo> nestPartTool(ReportNestPartToolReqVo reqVo) {
        return reportService.nestPartTool(reqVo);
    }

    @ApiOperation("预套料报表")
    @GetMapping("/preNestReport")
    public BaseListResVo<ReportPreNestResVo> preNestReport(ReportPreNestReqVo reqVo) {
        return reportService.preNestReport(reqVo);
    }

    @ApiOperation("预套料报表——新")
    @GetMapping("/preNestReportNew")
    public BaseListResVo<ReportPreNestNewResVo> preNestReportNew(ReportPreNestNewReqVo reqVo) {
        return reportService.preNestReportNew(reqVo);
    }

    @ApiOperation("预套料报表异常数据详情")
    @GetMapping("/preNestException")
    public BaseListResVo<ReportPreNestErrResVo> preNestException(ReportPreNestErrReqVo reqVo) {
        return reportService.preNestException(reqVo);
    }

    @ApiOperation("预套料报表-钢板详情")
    @GetMapping("/preNestPlate")
    public BasePageResVo<ReportPrePlateResVo> preNestPlate(ReportPrePlateReqVo reqVo) {
        return reportService.preNestPlate(reqVo);
    }

    @ApiOperation("预套料报表-钢板详情——新")
    @GetMapping("/preNestPlateNew")
    public BasePageResVo<ReportPrePlateResVo> preNestPlateNew(ReportPrePlateNewReqVo reqVo) {
        return reportService.preNestPlateNew(reqVo);
    }

    @ApiOperation("预套料-零件详情")
    @GetMapping("/preNestPart")
    public BaseListResVo<ReportPrePartResVo> preNestPart(ReportPrePartReqVo reqVo) {
        return reportService.preNestPart(reqVo);
    }

    @ApiOperation("套料报告-移植PDA")
    @GetMapping("/nestReportPda")
    public ReportNestReportPdaResVo nestReportPda(ReportNestReportPdaReqVo reqVo) {
        return reportService.nestReportPda(reqVo);
    }

    @ApiOperation("物料需求-原材料计划-钢板需求计划")
    @GetMapping("/nestPlateNeed")
    public ReportNestPlateNeedVo nestPlateNeed(ReportNestPlateNeedReqVo reqVo) {
        return reportService.nestPlateNeed(reqVo);
    }

    @ApiOperation("物料需求-原材料计划-钢板需求汇总")
    @GetMapping("/nestPlateSum")
    public ReportNestPlateSumVo nestPlateSum(ReportNestPlateSumReqVo reqVo) {
        return reportService.nestPlateSum(reqVo);
    }

    @ApiOperation("物料需求-零件信息")
    @GetMapping("/nestPartInfo")
    public BasePageResVo<ReportNestPartInfoResVo> nestPartInfo(ReportNestPartInfoReqVo reqVo) {
        return reportService.nestPartInfo(reqVo);
    }

    @ApiOperation("物料需求-原材料计划-焊丝需求计划")
    @GetMapping("/nestWireNeed")
    public BasePageResVo<ReportWireNeedResVo> nestWireNeed(ReportWireNeedReqVo reqVo) {
        return reportService.nestWireNeed(reqVo);
    }

    @ApiOperation("物料需求-原材料计划-喷粉需求计划")
    @GetMapping("/nestSprayNeed")
    public BasePageResVo<ReportSprayNeedResVo> nestSprayNeed(ReportSprayNeedReqVo reqVo) {
        return reportService.nestSprayNeed(reqVo);
    }

    @ApiOperation("手动强制解锁")
    @PostMapping("/unlockStock")
    public BaseResVo unlockStock(@RequestBody ReportUnlockStockReqVo reqVo) {
        reportService.unlockStock(reqVo);
        return BaseResVo.ok();
    }

    @ApiOperation("立体库库存信息获取")
    @GetMapping("/ltkInfo")
    public Map<String, ReportWireStockResVo> ltkInfo() {
        return reportService.ltkInfo();
    }

    @ApiOperation("接受套料回传信息")
    @GetMapping("/receiveNestInfo")
    public String receiveNestInfo(String body, String type) throws IOException {
        return reportService.receiveNestInfo(body, type);
    }

    @ApiOperation("工单发布————迁移添翼")
    @GetMapping("/getWorkOrderPublish")
    public BasePageResVo<ReportWorkOrderPublishResVo> getWorkOrderPublish(ReportWorkOrderPublishReqVo reqVo) {
        return reportService.getWorkOrderPublish(reqVo);
    }

    @ApiOperation("托盘开报工报表————迁移添翼")
    @GetMapping("/getPalletReport")
    public BasePageResVo<ReportPalletReportResVo> getPalletReport(ReportPalletReportReqVo reqVo) {
        return reportService.getPalletReport(reqVo);
    }

    @ApiOperation("生产计划达成率报表")
    @GetMapping("/planFinishReport")
    public BaseListResVo<ReportPlanFinishResVo> planFinishReport(ReportPlanFinishReqVo reqVo) {
        return reportService.planFinishReport(reqVo);
    }

    @ApiOperation("生产计划达成率——工作区下拉框")
    @GetMapping("/workAreaSelect")
    public BaseListResVo<AreaDetail> workAreaSelect() {
        return new BaseListResVo<>(reportService.workAreaSelect());
    }

    @ApiOperation("生产计划达成率——工序下拉框")
    @GetMapping("/phaseCodeSelect")
    public BaseListResVo<String> phaseCodeSelect() {
        return new BaseListResVo<>(reportService.phaseCodeSelect());
    }

    @ApiOperation("钢板区域计划达成率详情")
    @GetMapping("/planFinishDetailPl")
    public BaseListResVo<ReportPlanGroupPlResVo> planFinishDetailPl(ReportPlanGroupPlReqVo reqVo) {
        return reportService.planFinishDetailPl(reqVo);
    }

    @ApiOperation("零件区域计划达成率详情")
    @GetMapping("/planFinishDetailPa")
    public BaseListResVo<ReportPlanGroupPaResVo> planFinishDetailPa(ReportPlanGroupPaReqVo reqVo) {
        return reportService.planFinishDetailPa(reqVo);
    }

}
